package com.chaodev.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.ButtonDao;
import com.chaodev.base.dto.ButtonDTO;
import com.chaodev.base.model.Button;
import com.chaodev.base.model.ButtonPageVO;
import com.chaodev.base.service.IButtonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ButtonServiceImpl implements IButtonService {
    @Autowired
    private ButtonDao buttonDao;

    @Override
    public PageInfo<ButtonDTO> buttonQueryPage(ButtonPageVO dataPage) {
        PageHelper.startPage(dataPage.getPage(), dataPage.getRows());
        List<ButtonDTO> list = buttonDao.buttonQuery(dataPage);
        PageInfo<ButtonDTO> pageInfo = new PageInfo<>(list, dataPage.getRows());
        return pageInfo;
    }

    @Override
    public boolean buttonAdd(Button button) {
        int result;
        if (null != button.getButtonId() && !"".equals(button.getButtonId())) {
            result = buttonDao.buttonUpdate(button);
        } else {
            result = buttonDao.buttonAdd(button);
        }
        return result != 0;
    }

    @Override
    public boolean buttonDelete(Button button) {
        int result = buttonDao.buttonDelete(button);
        return result != 0;
    }

    @Override
    public List<ButtonDTO> getButtonType(Map<String, Object> map) {
        return buttonDao.getButtonType(map);
    }

    @Override
    public List<ButtonDTO> getMenuBtn(Map<String, Object> map) {
        return buttonDao.getMenuBtn(map);
    }

    @Override
    public boolean menuBtnDel(String menuId) {
        int result = buttonDao.menuBtnDel(menuId);
        return result != 0;
    }
}
